<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增订单')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-post-add">
        <input type="hidden" name="orderId" value="1"/>
        <div class="form-group">
            <label class="col-sm-5 control-label "><h1>项目信息:</h1></label>
        </div>
        <div class="form-group">
            <div class="form-group">
                <label class="col-sm-3 control-label ">订单编号（项目编号）：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="projectId" id="projectId"
                           onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)"
                           onblur="this.v();" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="projectTitle" id="projectTitle" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">订单类别：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="projectStyle">
                        <option th:each="order:${vos}" th:value="${order.orderStyle}">[[${order.orderStyle}]]</option>
                        <input type="hidden" name="orderId" value="1"/>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">项目状态：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="projectStatus">
                        <option value="0">关闭</option>
                        <option value="1">开启</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">项目完成时间：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="datetime-local" name="projectEndtime" id="projectEndtime"
                          STEP="1"
                           required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">项目总额：</label>
                <div class="col-sm-2">
                    <input class="form-control" type="text" name="projectSal" id="projectSal"
                           onblur="checkSal2(this)"
                           required>
                </div>


                <div class="col-sm-7" style="margin-bottom: 30px">
                    <h2>元(人民币)</h2>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="projectRemark" name="projectRemark" class="form-control"></textarea>
                </div>
            </div>
            <br>
            <div class="form-group">
                <label class="col-sm-5 control-label "><h1>付款信息:</h1></label>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">付款订单编号：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="scheduleId" id="scheduleId"
                           onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)"
                           onblur="this.v();"
                           required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">付款阶段：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="scheduleMoment" name="scheduleMoment" onclick="changePay()">
                        <option value="0">未完成</option>
                        <option  value="1">完成</option>
                    </select>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">付款方式：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="schedulePayment" >
                        <option value="微信">微信</option>
                        <option value="支付宝">支付宝</option>
                    </select>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">付款进度：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="schedulePaymentProgress" name="schedulePaymentProgress" disabled=true >
                        <option th:each="shcdule:${shcdule}" th:value="${shcdule}/100">[[${shcdule}]]%</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">付款备注：</label>
                <div class="col-sm-8">
                    <textarea id="scheduleRemark" name="scheduleRemark" class="form-control"></textarea>
                </div>
            </div>

            <!--客户-->
            <br>
            <div class="form-group">
                <label class="col-sm-5 control-label "><h1>客户信息:</h1></label>
            </div>
            <div class="form-group">

                <label class="col-sm-3 control-label ">客户编号：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="clientId" id="clientId"
                           onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)"
                           onblur="this.v();"
                           required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">客户名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="clientName" id="clientName" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">客户公司：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="clientCompany" id="clientCompany" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">客户类型：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="clientType">
                        <option value="VIP">VIP客户</option>
                        <option value="Normal">普通客户</option>
                    </select>

                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">客户电话：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="clientPhonenumber" id="clientPhonenumber" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">客户属性：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="clientPosition" id="clientPosition" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">客户备注：</label>
                <div class="col-sm-8">
                    <textarea id="clientRemark" name="clientRemark" class="form-control"></textarea>
                </div>
            </div>

            <!--订单-->
            <div class="form-group">
                <label class="col-sm-5 control-label "><h1>订单操作确认:</h1></label>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label "> 销售人员确认：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="crewName" id="crewName"
                           required>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label "> 部门负责人确认：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="deptName" id="deptName" th:value="${deptName}"/>
                    <input class="form-control" type="text" name="deptPrincipal" id="deptPrincipal"
                           required>
                </div>
            </div>

    </form>

</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "hcy/saleManagement";
   function changePay(){
       if ($("#scheduleMoment").val() != 0) {
           $("#schedulePaymentProgress").attr('disabled', false);
       }else{
           $("#schedulePaymentProgress").val("0")
           $("#schedulePaymentProgress").attr('disabled', true);
       }
   }


    function checkSal2(a) {
        if (a.value == "") {
            a.value = 0;
        }
        console.log(!a.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))
        /*判断是否是数字，如果不是，则值等于0 */
        if (!a.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/)) {
            a.value = 0;
        } else {
            console.log("2::"+a.value.match(/^\.\d+$/))
            if (a.value.match(/^\.\d+$/)) {
                a.value = 0 + a.value;
            }
            console.log("3::"+a.value.match(/^\.$/))
            if (a.value.match(/^\.$/)) {
                a.value = 0;
            }
        }
    }


    $("#projectSal").blur(function () {
        if ($(this).val() != null) {
            var number = parseFloat($(this).val()).toFixed(2);
            $(this).val(number)
        }
    })

    $("#form-post-add").validate({
        onkeyup: false,
        rules: {

            deptPrincipal: {
                remote: {
                    url: prefix + "/checkdeptPrincipal",
                    type: "post",
                    dataType: "json",
                    data: {
                        "deptName": function () {
                            return $.common.trim($("#deptName").val());
                        },
                        "deptPrincipal": function () {
                            return $.common.trim($("#deptPrincipal").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },

            crewName: {
                remote: {
                    url: prefix + "/checkCrewName",
                    type: "post",
                    dataType: "json",
                    data: {
                        "crewName": function () {
                            return $.common.trim($("#crewName").val());
                        },
                        "deptName": function () {
                            return $.common.trim($("#deptName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            projectId: {
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "projectId": function () {
                            return $.common.trim($("#projectId").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            projectTitle: {
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "projectTitle": function () {
                            return $.common.trim($("#projectTitle").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            clientId: {
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "clientId": function () {
                            return $.common.trim($("#clientId").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            scheduleId: {
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "scheduleId": function () {
                            return $.common.trim($("#scheduleId").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "projectTitle": {
                remote: "项目名称已经存在"
            },
            "scheduleId": {
                remote: "该编号已经存在"
            }
            ,
            "clientId": {
                remote: "该编号已经存在"
            },
            "projectId": {
                remote: "该编号已经存在"
            },
            "crewName": {
                remote: "该销售不存在"
            },
            "deptPrincipal": {
                remote: "该主理人输入有误，请重新输入"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-post-add').serialize());
        }
    }
</script>
</body>
</html>
